package com.hspedu.qqclient.view;

import com.hspedu.qqclient.service.UserClientService;
import com.hspedu.qqclient.utils.Utility;
import org.junit.Test;

import java.io.IOException;
import java.util.Scanner;

/**
 * @author DL5O
 * @version 1.0
 * 客服端的菜单界面
 */
public class QQView {
    private boolean loop = true;
    private String key = "";//用来接用户的键盘输入
    private UserClientService ucs = new UserClientService();//是用于登陆服务器/注册用户

    @Test
    //一级登陆菜单
    public void mainMenu() {
        while (loop) {
            System.out.println("========欢迎登录网络通讯系统========");
            System.out.println("\t\t 1 登录系统");
            System.out.println("\t\t 9 退出系统");
            System.out.print("请输入你的选择: ");
            key = Utility.readString(1);
            //根据用户的输入来处理不用的业务逻辑
            switch (key) {
                case "1":
//                    System.out.println("登陆系统...");
                    System.out.print("请输入用户名: ");
                    String userId = Utility.readString(50);
                    System.out.print("请输入密 码: ");
                    String pwd = Utility.readString(50);
                    //需要把数据传入到服务端进行验证，验证是否合法
                    //我们这里编写一个类UserClientService[用户登陆，用户注册]

                    boolean b = ucs.checkUser(userId, pwd);
                    if (b) {
                        System.out.println("登陆成功");
                        secondMenu(userId);//二级菜单
                    } else {
                        System.out.println("登陆失败...");
                        System.out.println("用户名或密码不正确请重新登陆...");
                    }
                    break;
                case "9":
                    loop = false;
                    System.out.println("退出系统...");
                    break;
                default:
                    System.out.println("请重新输入");
            }
        }

    }

    //二级菜单
    public void secondMenu(String userId) {
        System.out.println(userId + " 登陆成功...");
        System.out.println("========欢迎 (用户 " + userId + " )========");
        while (loop) {
            System.out.println("========网络通讯系统二级菜单========");
            System.out.println("\t\t 1 显示在线用户列表");
            System.out.println("\t\t 2 群发消息");
            System.out.println("\t\t 3 私聊消息");
            System.out.println("\t\t 4 发送文件");
            System.out.println("\t\t 9 退出系统");
            System.out.print("请输入选择:");
            key = Utility.readString(1);

            switch (key) {
                case "1":
                    System.out.println("显示在线用户列表...");
                    break;
                case "2":
                    System.out.println("群发消息...");
                    break;
                case "3":
                    System.out.println("私聊消息...");
                    break;
                case "4":
                    System.out.println("发送文件...");
                    break;
                case "9":
                    loop = false;
                    System.out.println("退出系统...");
                    break;
                default:
                    System.out.println("输入有误,请重新输入!");
                    break;
            }
        }
    }

}
